package com.ltu.excel.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.ltu.enums.EnumUtils;
import com.ltu.enums.SysDict.PayStatusEnum;

import lombok.extern.slf4j.Slf4j;

/**
 * roomType属性的转换
 * @author Administrator
 *
 */
@Slf4j
public class PayStatusConvert implements Converter<Integer> {

	  @Override
	    public Class supportJavaTypeKey() {
	        return Integer.class;
	    }
	  @Override
	    public CellDataTypeEnum supportExcelTypeKey() {
	        return CellDataTypeEnum.STRING;
	    }
	
	  
	  /**
	     * 读取String转换成Integer
	     * @param cellData
	     *            NotNull
	     * @param contentProperty
	     *            Nullable
	     * @param globalConfiguration
	     *            NotNull
	     * @return
	     */
	    @Override
	    public Integer convertToJavaData(ReadCellData cellData , ExcelContentProperty contentProperty,
	    		GlobalConfiguration globalConfiguration)throws Exception  {
	           
	    	PayStatusEnum dict =	EnumUtils.strToEnum(PayStatusEnum.class, cellData.getStringValue());
	   		if(null == dict)
	   			dict=PayStatusEnum.Status3;
	        return dict.getIndex();
	    }
	   
 
	    /**
	     *写入Excel
	     *
	     * @param value
	     *            NotNull
	     * @param contentProperty
	     *            Nullable
	     * @param globalConfiguration
	     *            NotNull
	     * @return
	     */
	    @Override
	    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty,
	        GlobalConfiguration globalConfiguration) {
	    	
	    	PayStatusEnum dict =	EnumUtils.indexToEnum(PayStatusEnum.class, value);
	   		if(null == dict)
	   			dict=PayStatusEnum.Status3;
	   		return	new WriteCellData(dict.getValue());
	    }


}
